﻿using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Linq;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {
        private void AFSARTLIST(DataSet db)
        {
            int x = 5, y = 1;

            int idx = 2;
            string VKPPOSTYP = "";
            DataTable dtOutput = new DataTable();
            try
            { 
                #region======Title===========
                exAgent.SetCellValue(x, idx++, "Barcode"); dtOutput.Columns.Add("VAAART", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "ART NO. "); dtOutput.Columns.Add("VAABEZ", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "Composition"); dtOutput.Columns.Add("VAAFILLER", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "Weight"); dtOutput.Columns.Add("WEIGHT", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "width"); dtOutput.Columns.Add("WIDTH", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "Code"); dtOutput.Columns.Add("CODE", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "Supplier"); dtOutput.Columns.Add("LSLIEFNA", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "Price"); dtOutput.Columns.Add("PRICE", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "Location"); dtOutput.Columns.Add("LOCATION", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "Book"); dtOutput.Columns.Add("BOOK", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "Remark"); dtOutput.Columns.Add("REMARK", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "Modify"); dtOutput.Columns.Add("VAAAENDBEN", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "Date"); dtOutput.Columns.Add("VAAAENDDAT", typeof(System.Decimal));
                exAgent.SetCellValue(x, idx++, "Create"); dtOutput.Columns.Add("VAANEUBEN", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "Date"); dtOutput.Columns.Add("VAANEUDAT", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "DelDate"); dtOutput.Columns.Add("VAASPERRDAT", typeof(System.String));
                #endregion 

                dtOutput.Clear();
                dtOutput.Merge(db.Tables["VAART"], false, MissingSchemaAction.Ignore); 
                 exAgent.DataTableToExcel(dtOutput, x+1, 2);
            } 

            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                EventDispatcher.Instance.RaiseStatus("完成", StatusEventType.StopProgress);
            }
        }
        private void AFSEXAPP(DataSet db)
        {
            try
            {
                string value = "";
                int x = 1, y = 1;
                int rown = 2;
                string processed = "";
                int idx = 0;
                int rowstart = 9;
                DataRow dwVKP;
                dwVKP = db.Tables["ICC_EXORD"].Rows[0];
                #region===Header============
                exAgent.SetCellValue(5, 4, dwVKP["CUSTOMER"].ToString().Trim());
                exAgent.SetCellValue(5, 29, dwVKP["VKPAUFKRS"].ToString() + dwVKP["VKPAUFLFD"].ToString());
                exAgent.SetCellValue(5, 15, dwVKP["CHAR5"].ToString().Trim());
                //exAgent.SetCellValue(6, 14, dwVKP["CHAR2"].ToString().Trim());
                //exAgent.SetCellValue(6, 20, dwVKP["CHAR3"].ToString().Trim());
                exAgent.SetCellValue(6, 29, year + "/" + month + "/" + day);
                exAgent.SetCellValue(4, 29, dwVKP["VKPNEUTIME"].ToString());
                #endregion                            
                int count = db.Tables["ICC_EXORD"].Rows.Count;
                foreach (DataRow row in db.Tables["ICC_EXORD"].Select("1=1", "VKPAUFPOS ASC"))
                {
                    if (row["VKPART"].ToString().Trim() == "") continue;                    
                    exAgent.SetCellValue(rowstart + rown * idx, 1, row["VKPAUFPOS"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx, 3, row["VKPARTDES"].ToString().TrimEnd());
                    exAgent.SetCellValue(rowstart + rown * idx, 7, row["CHAR1"].ToString());
                    exAgent.SetCellValue(rowstart + rown * idx, 11, row["COMPOSITION"].ToString());
                    exAgent.SetCellValue(rowstart + rown * idx, 17, row["GM"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx, 21, Helper.GetGB2312Value(row["VWIDTH"].ToString()).Trim());
                    exAgent.SetCellValue(rowstart + rown * idx, 26, row["REMARK"].ToString());
                    //exAgent.SetCellValue(rowstart + rown * idx, 11, row["QUANTITY"].ToString().Trim());
                    //exAgent.SetCellValue(rowstart + rown * idx, 28, row["PRICE"].ToString().Trim());// + row["CHAR1"].ToString().Trim());       
                    
                    idx++;
                    if (idx < count)
                    {
                        exAgent.RangeCopy(9, 10, rowstart + rown * idx, rowstart + rown * idx + 1);
                    }
                }
                exAgent.SetCellValue(rowstart + rown * idx + 1, 23, "Total:" + idx + " items");

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void AFSEXAPP1(DataSet db)
        {
            try
            {
                string value = "";
                int x = 1, y = 1;
                int rown = 2;
                string processed = "";
                int idx = 0;
                int rowstart = 9;
                DataRow dwVKP;
                dwVKP = db.Tables["ICC_EXORD"].Rows[0];
                #region===Header============
                exAgent.SetCellValue(5, 4, dwVKP["CUSTOMER"].ToString().Trim());
                exAgent.SetCellValue(5, 25, dwVKP["VKPAUFKRS"].ToString() + dwVKP["VKPAUFLFD"].ToString());
                exAgent.SetCellValue(5, 15, dwVKP["CHAR5"].ToString().Trim());
                //exAgent.SetCellValue(6, 14, dwVKP["CHAR2"].ToString().Trim());
                //exAgent.SetCellValue(6, 20, dwVKP["CHAR3"].ToString().Trim());
                exAgent.SetCellValue(6, 25, year + "/" + month + "/" + day);
                exAgent.SetCellValue(4, 25, dwVKP["VKPNEUTIME"].ToString());
                #endregion
                int count = db.Tables["ICC_EXORD"].Rows.Count;
                foreach (DataRow row in db.Tables["ICC_EXORD"].Select("1=1", "VKPAUFPOS ASC"))
                {
                    if (row["VKPART"].ToString().Trim() == "") continue;
                    exAgent.SetCellValue(rowstart + rown * idx, 1, row["VKPAUFPOS"].ToString().Trim());
                    //exAgent.SetCellValue(rowstart + rown * idx, 2, row["VKPART"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx, 3, row["VKPARTDES"].ToString().TrimEnd());
                    exAgent.SetCellValue(rowstart + rown * idx, 7, row["CHAR1"].ToString());
                    exAgent.SetCellValue(rowstart + rown * idx, 11, row["COMPOSITION"].ToString());
                    exAgent.SetCellValue(rowstart + rown * idx, 17, row["GM"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx, 21, Helper.GetGB2312Value(row["VWIDTH"].ToString()).Trim());                    
                    exAgent.SetCellValue(rowstart + rown * idx, 26, row["REMARK"].ToString());
                    exAgent.SetCellValue(rowstart + rown * idx, 31, row["PRICE"].ToString()); 

                    idx++;
                    if (idx < count)
                    {
                        exAgent.RangeCopy(9, 10, rowstart + rown * idx, rowstart + rown * idx + 1);
                    }
                }
                exAgent.SetCellValue(rowstart + rown * idx + 1, 23, "Total:" + idx + " items");

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void AFSEXAPP3(DataSet db)
        {
            try
            {
                string value = "";
                int x = 1, y = 1;
                int rown = 4;
                string processed = "";
                int idx = 0;
                int rowstart = 9;
                DataRow dwVKP;
                dwVKP = db.Tables["ICC_EXORD"].Rows[0];
                #region===Header============
                exAgent.SetCellValue(5, 4, dwVKP["CUSTOMER"].ToString().Trim());
                exAgent.SetCellValue(5, 30, dwVKP["VKPAUFKRS"].ToString() + dwVKP["VKPAUFLFD"].ToString());
                exAgent.SetCellValue(5, 15, dwVKP["CHAR5"].ToString().Trim());
                //exAgent.SetCellValue(6, 14, dwVKP["CHAR2"].ToString().Trim());
                //exAgent.SetCellValue(6, 20, dwVKP["CHAR3"].ToString().Trim());
                exAgent.SetCellValue(6, 30, year + "/" + month + "/" + day);
                #endregion
                int count = db.Tables["ICC_EXORD"].Rows.Count;
                foreach (DataRow row in db.Tables["ICC_EXORD"].Select("1=1", "VKPAUFPOS ASC"))
                {
                    if (row["VKPART"].ToString().Trim() == "") continue;
                    exAgent.SetCellValue(rowstart + rown * idx, 1, row["VKPAUFPOS"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx, 2, row["VKPART"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx, 3, row["VKPARTDES"].ToString().TrimEnd());
                    exAgent.SetCellValue(rowstart + rown * idx, 7, row["VKPFARBE"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx, 11, row["QUANTITY"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx, 28, row["PRICE"].ToString().Trim());// + row["CHAR1"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx + 2, 3, row["VKPART"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx + 2, 7, row["CHAR1"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx + 2, 13, row["CHAR4"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx + 2, 17, row["CHAR2"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx + 2, 22, row["CHAR3"].ToString().Trim());
                    exAgent.SetCellValue(rowstart + rown * idx, 17, Helper.GetGB2312Value(row["VWIDTH"].ToString()).Trim());
                   
                    exAgent.SetCellValue(rowstart + rown * idx, 22, row["REMARK"].ToString());
                    exAgent.SetCellValue(rowstart + rown * idx, 7, row["COMPOSITION"].ToString());
                    exAgent.SetCellValue(rowstart + rown * idx, 13, row["GM"].ToString().Trim());
                    //if (row["GM"].ToString().Trim().Contains("G") || row["GM"].ToString().Trim().Contains("g"))
                    //{
                    //    exAgent.SetCellValue(rowstart + rown * idx, 13, row["GM"].ToString().Trim());
                    //}
                    //else
                    //{
                    //    exAgent.SetCellValue(rowstart + rown * idx, 13, row["GM"].ToString().Trim());
                    //}
                    //exAgent.SetCellValue(rowstart+  rown * idx, 28, row["YARN"].ToString().Trim() );
                    //exAgent.SetCellValue(rowstart + rown * idx + 1, 1, "Remark:");
                    //exAgent.SetCellValue(rowstart + rown * idx + 1, 3, row["REMARK"].ToString());
                    //exAgent.SetCellValue(rowstart+ rown * idx+3, 3, "note:"+row["REMARK"].ToString());
                    idx++;
                    if (idx < count)
                    {
                        exAgent.RangeCopy(9, 12, rowstart + rown * idx, rowstart + rown * idx + 1);
                    }
                }
                exAgent.SetCellValue(rowstart + rown * idx + 1, 23, "Total:" + idx + " items");

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

    }
}
